from main import *
from sqlalchemy.orm import relationship

class Author(db.Model):
    __tablename__ = 'author'

    pid = db.Column(db.Integer, primary_key=True, autoincrement=True)
    app_id = db.Column(db.String(20), unique=True)
    app_name = db.Column(db.String(50), unique=True)

    def __init__(self, app_id, app_name):
        self.app_id = app_id
        self.app_name = app_name

    def __repr__(self):
        return "作者：{} --> {}".format(self.app_id, self.app_name)

class ArticalDetail(db.Model):
    __tablename__ = 'article_detail'

    pid = db.Column(db.Integer, primary_key=True, autoincrement=True)
    query_time = db.Column(db.String(20))
    title = db.Column(db.String(200))
    url = db.Column(db.String(200))
    created_at = db.Column(db.String(20))
    updated_at = db.Column(db.String(20))
    app_id = db.Column(db.String(20), db.ForeignKey('author.app_id'))
    read_amount = db.Column(db.Integer)
    comment_amount = db.Column(db.Integer)
    article_id = db.Column(db.String(200))

    # author_id = db.Column(db.String(20), db.ForeignKey('author.app_id'))
    author = relationship('Author', backref=db.backref('article_detail'))

    def __init(self, query_time, title, url, created_at, updated_at, app_id, read_amount, comment_amount, article_id):
        self.query_time = query_time
        self.title = title
        self.url = url
        self.created_at = created_at
        self.updated_at = updated_at
        self.app_id = app_id
        self.read_amount = read_amount
        self.comment_amount = comment_amount
        self.article_id = article_id


    def __repr__(self):
        return "<文章：{}|{}|{}>".format(self.title, self.url, self.author)
